package com.orange.modules.dao;

import java.sql.SQLException;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.modules.entity.AuthApplyFile;

@Repository
public class AuthApplyFileRepository {
	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthApplyFileDao authApplyFileDao;
	
	
	public void insertApplyFile(AuthApplyFile aaf) throws SQLException{
		authApplyFileDao.save(aaf);
	}
	
	public AuthApplyFile queryAuthApplyFileBySchoolId(String schoolId ,String subject) throws SQLException{
		String sql = "SELECT t.p_id as pid,t.s_id as sid, t.s_self_evaluation_filepath as selfEvaluationFilepath, t.s_self_evaluation_filename as selfEvaluationFilename,"
				+ " t.s_employment_distribution_filepath as employmentDistributionFilepath,t.s_employment_distribution_filename as employmentDistributionFilename,t.s_specialty_construction_filepath as specialtyConstructionFilepath,"
				+ " t.s_specialty_construction_filename as specialtyConstructionFilename,t.s_supporting_materials_filepath as supportingMaterialsFilepath,t.s_supporting_materials_filename as supportingMaterialsFilename,t.s_createtime as createtime,"
				+ " t.login_type as logintype FROM t_auth_apply_file t WHERE t.s_id =? ";
		if(StringUtils.isNotBlank(subject)){
			sql+="AND t.login_type = '"+subject+"'";
		}
		AuthApplyFile aaf = dbHelper.getBean(sql, AuthApplyFile.class, schoolId);
		return aaf;
	}
	
	public AuthApplyFile queryApplyFileById(String id){
		AuthApplyFile a = authApplyFileDao.findOne(id);
		return a;
	}
}
